home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Eagles Nest BBS 8
/
Eagles_Nest_Mac_Collection_Disc_8.TOAST
/
Developer Tools⁄Additions
/
TextPertDK#1
/
MPW C Sources & Examples.image
/
Example2
/
AppleScan.c
next >
Wrap
Text File
|
1991-10-25
|
12KB
|
417 lines
/*
This file implements the calls that are defined in the
APPLE SCANNER TECHNICAL REFERENCE MANUAL.
CAUTION: These calls are implemented for MPW 3.X or Higher.
For MPW version 2.XX, the calls must be checked.
The calls defined in the manual are implemented by DEVICE MANAGER CALLS,
and are the standard calls that Apple has defined for a scanner.
*/
#include <devices.h>
#include <files.h>
#include <quickdraw.h>
#include <string.h>
#include "AppleScan.h"
/* Opening and closing the driver */
/* ScOpen OpenDriver */
/* ScClose Closedriver */
/* Getting Standard Features */
#define ScGetStdFeaturesStCall 2
#define ScGetResStCall 3
#define ScGetHalfTonesStCall 4
/* Setting Scan Area */
#define ScSetScanAreaCtlCall 2
/* Reading Scanned Data */
/* ScDoScan ReadCall */
#define ScAbortScanCtlCall 1
/* Getting Advanced Features calls' code */
#define ScGetAdvFeaturesStCall 5
#define ScSetHtPatternCtlCall 4
#define ScSetGroup3CtlCall 5
#define ScSetNoHomeCtlCall 6
#define ScSetLampCtlCall 7
#define ScSetGrayMapCtlCall 8
#define ScSetThresHoldCtlCall 9
#define ScSetWaitButtonCtlCall 10
/***************************************************************************************/
/******************************* ROUTINE IMPLEMENTATION ********************************/
/***************************************************************************************/
/* Opening and Closing the standard driver */
/***************************************************************************************/
pascal OSErr ScOpen(Str255 Nombre, short *RefNum) /* Variation ; Also receives the name */
/* Opens the driver and reset the scanner to it default values. */
{
return OpenDriver(Nombre, RefNum);
}
/***************************************************************************************/
pascal OSErr ScClose(short RefNum)
/* Closes the driver and releases the scanner. */
{
return CloseDriver(RefNum);
}
/* Getting Standard Features */
/***************************************************************************************/
pascal OSErr ScGetStdFeatures(short RefNum,
ScStdFeaturesPtr stdFeaturesPtr,
short Length)
/* Gives the user a complete description of the features of the scanner, following the
structure described in the stdFeaturesRec returned. */
{
char NullStr[10];
ParamBlockRec ParamBl;
ParamBl.cntrlParam.ioCompletion = nil;
ParamBl.cntrlParam.ioCRefNum = RefNum;
strcpy(NullStr, "");
ParamBl.cntrlParam.ioNamePtr = (StringPtr)NullStr;
ParamBl.cntrlParam.csCode = ScGetStdFeaturesStCall;
((long *)ParamBl.cntrlParam.csParam)[0] = (long)stdFeaturesPtr;
/* will take position 0 and 1 of the short array */
ParamBl.cntrlParam.csParam[2] = Length;
return (PBStatus(&ParamBl, false));
}
/***************************************************************************************/
pascal OSErr ScGetRes(short RefNum,
short CompType,
ScResPtr ResPtr)
/* Returns an array with the resolutions supported by the scanner.
The number of Resolutions supported by the scanner is defined in the stdFeaturesRec. */
{
char NullStr[10];
ParamBlockRec ParamBl;
ParamBl.cntrlParam.ioCompletion = nil;
ParamBl.cntrlParam.ioCRefNum = RefNum;
strcpy(NullStr, "");
ParamBl.cntrlParam.ioNamePtr = (StringPtr)NullStr;
ParamBl.cntrlParam.csCode = ScGetResStCall;
ParamBl.cntrlParam.csParam[0] = CompType;
((long *)ParamBl.cntrlParam.csParam)[1] = (long)ResPtr;
/* will take position 1 and 2 of the short array */
return (PBStatus(&ParamBl, false));
}
/***************************************************************************************/
pascal OSErr ScGetHalfTones(short RefNum,
short CompType,
ScHalfTonePtr HalfTonePtr)
/* Returns the list of supported halftone patterns.
This list has the structure described in the schalftone array. */
{
char NullStr[10];
ParamBlockRec ParamBl;
ParamBl.cntrlParam.ioCompletion = nil;
ParamBl.cntrlParam.ioCRefNum = RefNum;
strcpy(NullStr, "");
ParamBl.cntrlParam.ioNamePtr = (StringPtr)NullStr;
ParamBl.cntrlParam.csCode = ScGetHalfTonesStCall;
ParamBl.cntrlParam.csParam[0] = CompType;
((long *)ParamBl.cntrlParam.csParam)[1] = (long)HalfTonePtr;
/* will take position 1 and 2 of the short array */
return (PBStatus(&ParamBl, false));
}
/* Setting Scan Area */
/***************************************************************************************/
pascal OSErr ScSetScanArea(short RefNum,
ScScanAreaPtr ScanAreaPtr)
/* Sets the area to scan, and also the parameters to use in the scan of that area. */
{
char NullStr[10];
ParamBlockRec ParamBl;
ParamBl.cntrlParam.ioCompletion = nil;
ParamBl.cntrlParam.ioCRefNum = RefNum;
strcpy(NullStr, "");
ParamBl.cntrlParam.ioNamePtr = (StringPtr)NullStr;
ParamBl.cntrlParam.csCode = ScSetScanAreaCtlCall;
((long *)ParamBl.cntrlParam.csParam)[0] = (long)ScanAreaPtr;
/* will take position 1 and 2 of the short array */
return (PBControl(&ParamBl, false));
}
/* Reading Scanned Data */
/***************************************************************************************/
pascal OSErr ScDoScan(short RefNum,
Ptr Buffer,
long *Count,
short Unused,
short ByteWidth,
short RowBytes)
/* Starts scan and returns data following the parameters previously set. */
{
char NullStr[10];
ParamBlockRec ParamBl;
short Error;
ParamBl.cntrlParam.ioCompletion = nil;
ParamBl.cntrlParam.ioCRefNum = RefNum;
strcpy(NullStr, "");
ParamBl.cntrlParam.ioNamePtr = (StringPtr)NullStr;
ParamBl.ioParam.ioReqCount = *Count;
ParamBl.ioParam.ioBuffer = Buffer;
ParamBl.ioParam.ioPosMode = Unused;
ParamBl.ioParam.ioPosOffset = ((long)ByteWidth << 16) | (long)RowBytes;
Error = PBRead(&ParamBl, false);
*Count = ParamBl.ioParam.ioActCount;
return (Error);
}
/***************************************************************************************/
pascal OSErr ScAbortScan(short RefNum)
/* Aborts the scan in progress. Is the only call that the scanner
will answer to while a scan is being done. */
{
char NullStr[10];
ParamBlockRec ParamBl;
ParamBl.cntrlParam.ioCompletion = nil;
ParamBl.cntrlParam.ioCRefNum = RefNum;
strcpy(NullStr, "");
ParamBl.cntrlParam.ioNamePtr = (StringPtr)NullStr;
ParamBl.cntrlParam.csCode = ScAbortScanCtlCall;
return (PBControl(&ParamBl, false));
}
/* Getting Advanced Features */
/***************************************************************************************/
pascal OSErr ScGetAdvFeatures(short RefNum,
ScAdvFeaturesPtr AdvFeaturesPtr,
short Length)
/* Gives the user avdanced features of the scanner. Returns a
handle to ScAdvFeaturesRec. If a scanner doesn't support this call,
a statuserr value of -18 is returned. */
{
char NullStr[10];
ParamBlockRec ParamBl;
ParamBl.cntrlParam.ioCompletion = nil;
ParamBl.cntrlParam.ioCRefNum = RefNum;
strcpy(NullStr, "");
ParamBl.cntrlParam.ioNamePtr = (StringPtr)NullStr;
ParamBl.cntrlParam.csCode = ScGetAdvFeaturesStCall;
((long *)ParamBl.cntrlParam.csParam)[0] = (long)AdvFeaturesPtr;
/* will take position 0 and 1 of the short array */
ParamBl.cntrlParam.csParam[2] = Length;
return (PBStatus(&ParamBl, false));
}
/***************************************************************************************/
pascal OSErr ScSetHtPattern(short RefNum,
ScPatPtr PatPtr)
/* Sets the downloadable halftone pattern */
{
char NullStr[10];
ParamBlockRec ParamBl;
ParamBl.cntrlParam.ioCompletion = nil;
ParamBl.cntrlParam.ioCRefNum = RefNum;
strcpy(NullStr, "");
ParamBl.cntrlParam.ioNamePtr = (StringPtr)NullStr;
ParamBl.cntrlParam.csCode = ScSetHtPatternCtlCall;
((long *)ParamBl.cntrlParam.csParam)[0] = (long)PatPtr;
/* will take position 1 and 2 of the short array */
return (PBControl(&ParamBl, false));
}
/***************************************************************************************/
pascal OSErr ScSetGroup3(short RefNum,
Boolean CompressOn)
/* Enables and disables data compression in data returned by the scanner.
The compression used is Group III, 1-dimensional standard FAX encoding. */
{
char NullStr[10];
ParamBlockRec ParamBl;
ParamBl.cntrlParam.ioCompletion = nil;
ParamBl.cntrlParam.ioCRefNum = RefNum;
strcpy(NullStr, "");
ParamBl.cntrlParam.ioNamePtr = (StringPtr)NullStr;
ParamBl.cntrlParam.csCode = ScSetGroup3CtlCall;
ParamBl.cntrlParam.csParam[0] = ((CompressOn) ? (1) : (0));
return (PBControl(&ParamBl, false));
}
/***************************************************************************************/
pascal OSErr ScSetNoHome(short RefNum,
Boolean NoHome)
/* This function control whether or not the carriage assembly returns
to the home position after scanning. */
{
char NullStr[10];
ParamBlockRec ParamBl;
ParamBl.cntrlParam.ioCompletion = nil;
ParamBl.cntrlParam.ioCRefNum = RefNum;
strcpy(NullStr, "");
ParamBl.cntrlParam.ioNamePtr = (StringPtr)NullStr;
ParamBl.cntrlParam.csCode = ScSetNoHomeCtlCall;
ParamBl.cntrlParam.csParam[0] = ((NoHome) ? (1) : (0));
return (PBControl(&ParamBl, false));
}
/***************************************************************************************/
pascal OSErr ScSetLamp(short RefNum,
Boolean LampOn)
/* This call turns the fluorescent lamp On and Off. */
{
char NullStr[10];
ParamBlockRec ParamBl;
ParamBl.cntrlParam.ioCompletion = nil;
ParamBl.cntrlParam.ioCRefNum = RefNum;
strcpy(NullStr, "");
ParamBl.cntrlParam.ioNamePtr = (StringPtr)NullStr;
ParamBl.cntrlParam.csCode = ScSetLampCtlCall;
ParamBl.cntrlParam.csParam[0] = ((LampOn) ? (1) : (0));
return (PBControl(&ParamBl, false));
}
/***************************************************************************************/
pascal OSErr ScSetGrayMap(short RefNum,
short GrayMap)
/* Sets the gray map curve used while scanning. */
{
char NullStr[10];
ParamBlockRec ParamBl;
ParamBl.cntrlParam.ioCompletion = nil;
ParamBl.cntrlParam.ioCRefNum = RefNum;
strcpy(NullStr, "");
ParamBl.cntrlParam.ioNamePtr = (StringPtr)NullStr;
ParamBl.cntrlParam.csCode = ScSetGrayMapCtlCall;
ParamBl.cntrlParam.csParam[0] = GrayMap;
return (PBControl(&ParamBl, false));
}
/***************************************************************************************/
pascal OSErr ScSetThresHold(short RefNum,
short Threshold)
/* Sets the AutoBackground threshold level. */
{
char NullStr[10];
ParamBlockRec ParamBl;
ParamBl.cntrlParam.ioCompletion = nil;
ParamBl.cntrlParam.ioCRefNum = RefNum;
strcpy(NullStr, "");
ParamBl.cntrlParam.ioNamePtr = (StringPtr)NullStr;
ParamBl.cntrlParam.csCode = ScSetThresHoldCtlCall;
ParamBl.cntrlParam.csParam[0] = Threshold;
return (PBControl(&ParamBl, false));
}
/***************************************************************************************/
pascal OSErr ScSetWaitButton(short RefNum,
Boolean WaitButton)
/* This function controls if the scan will begin after a
DoScan command is send or if the scanner will wait for the
button it has to be pressed before beginning to scan. */
{
char NullStr[10];
ParamBlockRec ParamBl;
ParamBl.cntrlParam.ioCompletion = nil;
ParamBl.cntrlParam.ioCRefNum = RefNum;
strcpy(NullStr, "");
ParamBl.cntrlParam.ioNamePtr = (StringPtr)NullStr;
ParamBl.cntrlParam.csCode = ScSetWaitButtonCtlCall;
ParamBl.cntrlParam.csParam[0] = ((WaitButton) ? (1) : (0));
return (PBControl(&ParamBl, false));
}